<template>
  <a-modal
    :title="title"
    :visible="openDialog"
    :maskClosable="false"
    :destroyOnClose="true"
    @ok="confirmBtn('commonForm')"
    @cancel="mainDialogClose('commonForm')"
  >
    <a-form-model ref="commonForm" :model="formData" :rules="rules" v-bind="layout">
      <a-form-model-item label="名称" prop="title">
        <a-input v-model="formData.title" />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
// import api from '@/api/API';

export default {
  name: 'detailPartDialog',
  props: {
    openDialog: Boolean,
    title: String,
  },
  components: {},
  data() {
    return {
      // username: '',
      // role: '',
      // compId: '',
      // compType: '',
      mouldId: '',
      lists: [],
      formData: {
        title: '',
      },
      rules: {
        title: {
          required: true,
          min: 1,
          max: 70,
          message: '请输入1-70位之间的字符',
          trigger: 'blur',
        },
      },
      layout: {
        layout: 'horizontal',
        labelAlign: 'right',
        hideRequiredMark: true,
        labelCol: { span: 5 },
        wrapperCol: { span: 18 },
      },
    };
  },
  watch: {
    openDialog: {
      immediate: false,
      handler: async function(newVal, oldVal) {},
    },
  },
  methods: {
    mainDialogClose(formName) {
      this.$refs[formName].resetFields();
      this.$emit('update:openDialog', false);
    },
    confirmBtn(formName) {
      let _this = this;
      _this.$refs[formName].validate(async (valid) => {
        let { title } = _this.formData;

        //api注释
        // const res = await api.processInfoAdd({ name: title, mouldId: this.mouldId, prompt: 'das' });
        const res = {
          code: 200,
          data: 118,
          message: "message.common.success",
          success: null
        }
        if (res.code != 200) {
          this.$message.error('创建步骤失败');
          return;
        }
        let stepId = res.data;
        _this.$emit('confirmRefreshData', { stepId, title });
        _this.$refs[formName].resetFields();
        _this.$emit('update:openDialog', false);
      });
    },
  },
  mounted() {},
  created() {
    let { mouldId } = this.$route.query;
    this.mouldId = mouldId;
  },
};
</script>

<style scoped></style>
